//
//  ManagerAddressTableViewCell.m
//  beautyLamp
//
//  Created by Tam Kwok To Michael on 2017/8/17.
//  Copyright © 2017年 Tam Kwok To Michael. All rights reserved.
//

#import "ManagerAddressTableViewCell.h"
#import "Address.h"
#import "BLHeader.h"

@interface ManagerAddressTableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *telLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UIView *approveView;
@property (weak, nonatomic) IBOutlet UIView *editView;
@property (weak, nonatomic) IBOutlet UIView *deleteView;
@property (weak, nonatomic) IBOutlet UIButton *approveBtn;
@property (weak, nonatomic) IBOutlet UILabel *approveLabel;
@property (nonatomic, strong) Address *address;

@end


@implementation ManagerAddressTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setupCell:(Address *)address {
    self.address = address;
    self.nameLabel.text = address.name;
    self.telLabel.text = address.tel;
    self.addressLabel.text = address.address;
    
    if([address.isApprove isEqualToString:@"是"]) {
        [self.approveBtn setSelected:YES];
        self.approveLabel.textColor = kAppThemeColor;
    }else {
        [self.approveBtn setSelected:NO];
        self.approveLabel.textColor = [UIColor blackColor];

    }
    
    UITapGestureRecognizer *approve = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(approveEvent)];
    [self.approveView addGestureRecognizer:approve];
    
    UITapGestureRecognizer *edit = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(editAddress)];
    [self.editView addGestureRecognizer:edit];
    
    UITapGestureRecognizer *delete = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deleteAddress)];
    [self.deleteView addGestureRecognizer:delete];
    
}


- (IBAction)approveBtnEvent:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(approveAddress:label:address:)]) {
        [self.delegate approveAddress:self.approveBtn label:self.approveLabel address:self.address];
    }
}

// 设置为默认地址
- (void)approveEvent {
    if ([self.delegate respondsToSelector:@selector(approveAddress:label:address:)]) {
        [self.delegate approveAddress:self.approveBtn label:self.approveLabel address:self.address];
    }
}

- (void)editAddress {
    if ([self.delegate respondsToSelector:@selector(deleteAddress:)]) {
        [self.delegate deleteAddress:self.address];
    }
}


- (void)deleteAddress {
    if ([self.delegate respondsToSelector:@selector(editAddress:)]) {
        [self.delegate editAddress:self.address];
    }
}
@end
